<?php
require('config.php');

		$sql="select * from `".$oto."_goods_cats` where catFlag=1 and isFixed=0 and isShow=1 order by parentId ASC,catSort ASC";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$cat_list[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$t=0;
		if(isset($cat_list))
		{
			for($i=0;$i<count($cat_list);$i++)
			{
				if($cat_list[$i]['parentId']==0)
				{
					$cat_id=$cat_list[$i]['catId'];
					$time=date('Y-m-d');
					$sql="select * from `".$oto."_ads` where `adPositionId`='".$cat_id."' and `adStartDate`<='$time' and `adEndDate`>='$time'";
					$result=$db->query($sql);
					while($row=$result->fetch_assoc()){
						$ads[$t][]=$row;//将取得的所有数据赋值给person_info数组
					}
					if(isset($ads[$t]))
					{
						$cat_list[$i]['cateImg']=$ads[$t][0]['adFile'];
						$cat_list[$i]['adURL']=$ads[$t][0]['adURL'];
						$cat_list[$i]['adId']=$ads[$t][0]['adId'];
						$cat_list[$i]['adURLApp']=$ads[$t][0]['adURLApp'];
					}
					else
					{
						$cat_list[$i]['cateImg']='';
					}
					$t++;
				}
			}
			echo json_encode($cat_list);
		}
		else
		{
			echo '[]';
		}
		
?>